package com.kk.util.test.thread.example;

/**
 * @function:
 * @author: kevin
 * @date: 2018-09-07 18:17
 */
public class ProductThread extends Thread {
    private ObjectData data;

    public ProductThread(ObjectData data) {
        this.data = data;
    }

    public void run() {
        while (true) {
            try {
                synchronized (data) {
                    if (data.getCount() < 20) {
                        data.product();
                    } else {
                        Thread.sleep(2000);
                    }
                    data.notify();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
